#include <yuv.h>
#include <stdio.h>
#include <stdlib.h>
/**
 *提出YUV格式的原因，是为了解决彩色电视和黑白电视兼容性问题，因此从rgb的颜色空间，转换为yuv的颜色空间，其中y代表亮度，u和v代表色度。
 * @param filePath
 * @param width
 * @param height
 */
void yuv420(const char* filePath, int width, int height){
    FILE* fp = fopen(filePath, "rb+");
    FILE* fpy = fopen("yuv420_y.y", "wb+");
    FILE* fpu = fopen("yuv420_u.y", "wb+");
    FILE* fpv = fopen("yuv420_v.y", "wb+");

    unsigned  char* p = (unsigned char*)malloc(width * height * 3 / 2);

    int i = 0;
    while (i < 20){ //写20帧
        fread(p, 1, width * height * 3 / 2, fp);
        //y 亮度
        fwrite(p, 1, width * height, fpy); //1
        //u
        fwrite(p + width * height, 1, width * height / 4, fpu);// 1/4
        //v
        fwrite(p + (width * height) + (width * height / 4), 1, width * height / 4, fpv); // 1/4
        i++;
    }
    free(p);
    p = NULL;
    fclose(fp);
    fclose(fpy);
    fclose(fpu);
    fclose(fpv);
}